package com.shihb.homework

object OopHomework {

  def main(args: Array[String]): Unit = {
    val woker:Employee = new Woker("工人", 100.00)
    val manager:Employee = new Manager("管理者", 1000.00, 666.66)
    showEmpAnnal(woker)
    showEmpAnnal(manager)
    testWork(woker)
    testWork(manager)

  }
  def showEmpAnnal(e:Employee){
    println(e.name,e.getAnnual)
  }
  def testWork(e:Employee): Unit ={
    if(e.isInstanceOf[Woker]) e.asInstanceOf[Woker].work else e.asInstanceOf[Manager].manager
  }
}
class Employee(var name:String,var sal:Double){
  def getAnnual={
    sal*12
  }
}
class Woker(name:String,sal:Double) extends Employee(name,sal){
  def work: Unit ={
    println(name+"working")
  }
}
class Manager(name:String,sal:Double,var bonus: Double) extends Employee(name,sal){
  def manager: Unit ={
    println(name+"managing")
  }
  override def getAnnual: Double = {
    super.getAnnual+bonus
  }

}
